<?php
require_once("inc.member.php");

$this_title="$vars[member_title] &raquo; ".__("Upload File");
$page_title=__("Upload File");
$content_title=__("Upload File");

$item_per_page=$vars["user_item_per_page"];
$td_width=180;


	//#####COMMISSION GET#####
if($_POST["__req"]){
	if ($_FILES["upload_file"]["error"] > 0)
	{
	  echo "Error: " . $_FILES["upload_file"]["error"] . "<br>";
	}
	else
	{
	  $filename = date('YmdHis')."_".$uid.'_'.$_FILES["upload_file"]["name"];
	  move_uploaded_file($_FILES["upload_file"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/upload/" .$filename);
	  $datetime = date('Y-m-d H:i:s');
	  
	  $sql="insert into $db->upload (uid, uremark, filename, cdate) values ($uid, '$_POST[uremark]', '$filename', '$datetime')";

	  if(!mysql_query($sql)){
		echo __("We have encountered some error and the registration process has been failed.")."<br />\n".($vars['debug']? "<br />\nSQL: $sql<br />\n<br />\nError: ".mysql_error()."<br />\n" : "");
	  }
	}
}


			$comm_query = true;

			$count_sql="select count(*) from $db->upload where uid='$uid' order by cdate desc";
			$record_sql="select * from $db->upload where uid='$uid' order by cdate desc limit <%limit_start%>, <%limit%>";
			
			$cur_page=$_POST["nav"];
			$total_record=@mysql_result(mysql_query($count_sql), 0);
			$total_page=ceil($total_record/$item_per_page);
			$page=($cur_page? ($cur_page>$total_page? $total_page : ($cur_page<1? 1 : $cur_page)) : 1);
			$limit_start=($page-1)*$item_per_page;
			$nav_link=format_page_admin($page, $total_page, $this_file);
			$this_page_total=@mysql_num_rows($r=mysql_query(str_replace("<%limit_start%>", $limit_start, str_replace("<%limit%>", $item_per_page, $record_sql))));
			$grand_total = @mysql_result(mysql_query($sum_sql), 0) or 0;
			$k=0;
			for($i=0;$i<$this_page_total;$i++){
				$comm=mysql_fetch_assoc($r);
				$this_no = ($page - 1) * $item_per_page + $i + 1;
				//maintenance
				
				$comm_row.="
					<tr class='row$k'>
						<td class='left'>".$this_no."</td>
						<td class='left'>".$comm['uremark']."</td>
						<td class='left'>".$comm['aremark']."</td>
						<td class='left'>".$comm['status']."</td>
						<td class='left'>".date($vars['date_format'], strtotime($comm['cdate']))."</td>
					</tr>";
				$k=1-$k;
			}

			//listing text
			$listing_text=replace_tag(__("Listing <%x%> <%comm%>."), array("<%x%>"=>strval($total_record), "<%comm%>"=>$total_record>1? __("files") : __("file")));

			//comm header
			$header_row = "
				<tr class='pbl_header'>
					<td>".__("Trans#")."</td>
					<td>".__("Remark")."</td>
					<td>".__("Admins Remark")."</td>
					<td>".__("Status")."</td>
					<td>".__("Date")."</td>					
				</tr>";
			
			//listing
			$comm_list=
			"
			$listing_text<br>$nav_link
			<table class='pbl_table'>
				$header_row
				$comm_row
			</table>";


	$errmsg=$errmsg? format_err(__("There is some error(s), please correct them before continuing:")."<br />\n<br />\n$errmsg") : "";

//#####END COMMISSION GET#####


//javascript
//ob_start();
?>
<script type='text/javascript' src='<?php echo JS_URL."/get_file_gzip.php?file=".urlencode("jquery.js,jquery.datepicker.js"); ?>'></script>
<script>
function formchecking() {
	if (document.getElementById('upload_file').value == '') {
		alert('<?php echo __('Please select file to upload!'); ?>');
		return false;
	}
}
</script>

<style type="text/css">
.uploadbox {
font-family: verdana, arial, sans-serif;
font-size: 100%;
color: #800000;
font-weight: normal;
border: #797979 1px solid;
background-color: #F3F781;
border-color: brown;
width: 292px;
height: 22px;
}
</style>

<?php
//$jvscript = ob_get_clean();

//css
ob_start();
?>
<link rel="stylesheet" href="<?php echo CSS_URL; ?>/jstheme/ui-lightness/jquery-ui.css" type="text/css" />
<?php
$css .= ob_get_contents();
ob_end_clean();

$upload_ui=($errmsg || $msg? $errmsg.$msg : "").
"<form name='upload_form' method='post' action='$this_file' enctype='multipart/form-data'>
<input type='hidden' name='__req' value='1' />
<input type='hidden' name='nav' value=\"$get_h[nav]\" />
<table class='pbt_table'>
	<tr>
		<td>".__("Upload File").__(":")." <input name='upload_file' id='upload_file' class='uploadbox' type='file' onkeypress='return false' /></td>
	</tr>
	<tr>
		<td>".__("Remark").__(":")." <textarea name='uremark' id='uremark' cols=40 rows=5></textarea></td>
	</tr>
	<tr>
		<td><input type='submit' value=\"".__("Submit")."\"  onclick='return formchecking()' /></td>
	</tr>
</table>
<br><hr><br>
</form>";

//$content="<h2>$page_title</h2>$upload_ui$comm_list";
$content=$upload_ui.$comm_list;

print format_member_page($content, $this_title, $content_title, $css.$jvscript);
?>